package com.beidouapp.translate;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.config.BeanPostProcessor;

import com.beidouapp.translator.TranslatorManager;

public class TranslatorScanner implements BeanPostProcessor, BeanFactoryAware
{
    private BeanFactory m_factory;

    @Override
    public Object postProcessAfterInitialization (Object object, String beanName) throws BeansException
    {
        if (object instanceof Translator)
        {
            Translator translator = (Translator) object;
            TranslatorManager translatorManager = 
                (TranslatorManager) m_factory.getBean ("translatorManager");
            translatorManager.addTranslator (translator);
        }
  
        return object;
    }

    @Override
    public Object postProcessBeforeInitialization (Object object, String beanName) throws BeansException
    {
        return object;
    }

    @Override
    public void setBeanFactory (BeanFactory factory) throws BeansException
    {
        m_factory = factory;
    }
    
}
